package com.shawn.spring.boot.websocket.job;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author shawn
 * @since 2020/9/8
 */
@Component
public class MessageJob {

  @Autowired private SimpMessagingTemplate template;

  @Scheduled(fixedRate = 1000)
  public void sendMessage() {
    template.convertAndSend("/topic/message", System.currentTimeMillis());
  }

  @Scheduled(fixedRate = 3000)
  public void sendMessageToUser() {
    template.convertAndSendToUser("2", "/message", System.currentTimeMillis());
  }
}
